package com.example.foo.account.dao;

import org.apache.commons.lang3.StringUtils;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.core.PageResult;
import com.example.core.Pageable;
import com.example.foo.account.model.AccountItem;
import com.example.foo.account.query.AccountItemQuery;

@org.apache.ibatis.annotations.Mapper
public interface AccountItemDao extends com.example.core.dao.BaseDao<AccountItem, Long> {

	public default PageResult<AccountItem> findAccountItems(AccountItemQuery accountItemQuery, Pageable pageable) {
		QueryWrapper<AccountItem> queryWrapper = createQueryWithBaseIf(accountItemQuery);
		//
		if (accountItemQuery.getAcctc() != null) {
			queryWrapper.eq("acctc", accountItemQuery.getAcctc());
		}
		if (accountItemQuery.getDrcr() != null) {
			queryWrapper.eq("drcr", accountItemQuery.getDrcr());
		}
		if (StringUtils.isNotEmpty(accountItemQuery.getName())) {
			queryWrapper.like("name", accountItemQuery.getName());
		}
		if (accountItemQuery.getUserId() != null) {
			queryWrapper.eq("user_id", accountItemQuery.getUserId());
		}
		if (accountItemQuery.getAnotherUserId() != null) {
			queryWrapper.eq("another_user_id", accountItemQuery.getAnotherUserId());
		}
		if (StringUtils.isNotEmpty(accountItemQuery.getRelType())) {
			queryWrapper.eq("rel_type", accountItemQuery.getRelType());
		}
		if (accountItemQuery.getRelId() != null) {
			queryWrapper.eq("rel_id", accountItemQuery.getRelId());
		}
		if (accountItemQuery.getPeriodMonth() != null) {
			queryWrapper.eq("period_month", accountItemQuery.getPeriodMonth());
		}
		if (accountItemQuery.getPeriodDay() != null) {
			queryWrapper.eq("period_day", accountItemQuery.getPeriodDay());
		}
		if (accountItemQuery.getPeriodDayFrom() != null) {
			queryWrapper.ge("period_day", accountItemQuery.getPeriodDayFrom());
		}
		if (accountItemQuery.getPeriodDayTo() != null) {
			queryWrapper.le("period_day", accountItemQuery.getPeriodDayTo());
		}
		return findPages(queryWrapper, pageable);
	}

}
